package com.javase;
/*
=======方法重载
 */
public class OverLoad01 {
    public static void main(String[] args) {
        MyCalculator myCalculator = new MyCalculator();
        System.out.println(myCalculator.calculate(1.1,2));
        Methods methods = new Methods();
        methods.m(6,7);
        methods.m(6);
        methods.m("hello world");
        System.out.println(methods.max(1645464,4654321));
        System.out.println(methods.max(12.3,12.2));
        System.out.println(methods.max(12.3,12.2,13.2));
    }
}

class MyCalculator{
    //四个方法构成重载（方法名一样，形参不同）
    //方法重载和返回类型无关，由形参判断，形参类型不同，顺序不同，个数不同都可以构成重载
    public int calculate(int n1,int n2){
        return n1 + n2;
    }
    public double calculate(int n1,double n2){
        return n1 + n2;
    }
    public double calculate(double n2,int n1){
        return n1 + n2;
    }
    public int calculate(int n1,int n2,int n3){
        return n1 + n2 + n3;
    }
}

class Methods{
    public void m(int n){
        System.out.println("平方是"+n*n);
    }
    public void m(int n1,int n2){
        System.out.println("相乘是"+n1*n2);
    }
    public void m(String n){
        System.out.println("字符串是"+n);
    }
    public int max(int n1,int n2){
        return Math.max(n1,n2);
    }
    public double max(double n1,double n2){
        return Math.max(n1,n2);
    }
    public double max(double n1,double n2,double n3){
        double n = Math.max(n1,n2);
        return Math.max(n,n3);
    }
}